module.exports = {
    parseCode(code, bt = '\\x'){
        let buf = Buffer.from(code.replace(/\s+/g, ' '))
        let json = buf.toJSON()
        let arr = json.data.map(n => {
            return bt+n.toString(16)
        })
        return arr.join('')
    },
    parsePswd(pswd){
        try{
            let arr = pswd.split(/[\*\/\^\&\$\#\@\|\!\_]+/), len = arr.length, newArr = []
            for(let i=0; i<len; i+=2){
                newArr[arr[i]] = arr[i+1]
            }
            return Buffer.from(newArr.join(''), 'base64').toString()
        }catch(err){
            console.error('parsePswd：', err.message)
            return ''
        }
    },
    parse(str){
        if(!Array.isArray(str)){
            str = decodeURIComponent(str)
            str = str.split(/\s+/)
        }
        return str.map(c => this.parsePswd(c))
    }
}